package com.hnkywl.jip.action;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.hnkywl.jip.service.BasicService;
import com.hnkywl.jip.service.CompanyService;
import com.hnkywl.jip.utils.BankData;
import com.hnkywl.jip.utils.VoucherItemData;
import com.hnkywl.jip.utils.VoucherMasterData;
import net.ruixin.web.struts2.SimpleActionSupport;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;

import java.lang.reflect.Type;
import java.util.Date;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: ZHUCHG
 * Date: 13-3-10
 * Time: 下午7:50
 * To change this template use File | Settings | File Templates.
 */
@Namespace("/voucher_fill")
public class VoucherFillAction extends SimpleActionSupport {
    private Date systemDate;
    private List<Object[]> companyList;

    private String voucherMaster;
    private String voucherItems;

    private BasicService basicService;
    private CompanyService companyService;


    @Action("voucher")
    public String voucher() {
        systemDate = new Date();
        companyList = companyService.searchAllCompany();
        return SUCCESS;
    }

    @Action("save_voucher")
    public void saveVoucher() {
        Gson gson =  new GsonBuilder().setDateFormat("yyyy-MM-dd").create();
        Type type = new TypeToken<List<VoucherItemData>>() {
        }.getType();
        VoucherMasterData voucherMasterData = gson.fromJson(voucherMaster, VoucherMasterData.class);
        List<VoucherItemData> voucherItemDataList = gson.fromJson(voucherItems, type);
        System.out.print("1");
    }
    //==========getter setter=================

    //=============getter=================
    public List<Object[]> getCompanyList() {
        return companyList;
    }

    public Date getSystemDate() {
        return systemDate;
    }

    //=============setter=================
    public void setVoucherMaster(String voucherMaster) {
        this.voucherMaster = voucherMaster;
    }

    public void setVoucherItems(String voucherItems) {
        this.voucherItems = voucherItems;
    }

    @Autowired
    public void setBasicService(BasicService basicService) {
        this.basicService = basicService;
    }

    @Autowired
    public void setCompanyService(CompanyService companyService) {
        this.companyService = companyService;
    }
}
